MODULE SUSDP_DFLT_CTL_MOD
CONTAINS
SUBROUTINE SUSDP_DFLT_CTL(PTVL, PTVH, PSLT, KLEVS3D, PSSDP2, PSSDP3, YDVEG, YDSOIL, YDAGS)

USE PARKIND1, ONLY : JPIM, JPRB
USE YOMHOOK , ONLY : LHOOK, DR_HOOK, JPHOOK
USE YOS_VEG , ONLY : TVEG
USE YOS_SOIL, ONLY : TSOIL
USE YOS_AGS , ONLY : TAGS
USE YOMSURF_SSDP_MOD

! (C) Copyright 2025- ECMWF.
!
! This software is licensed under the terms of the Apache Licence Version 2.0
! which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
! In applying this licence, ECMWF does not waive the privileges and immunities
! granted to it by virtue of its status as an intergovernmental organisation
! nor does it submit to any jurisdiction.

!     ---------------------------------------------------------------------------
!**   *SUSDP_DFLT* - INITIALIZE THE SDP PARAMETERS WITH DEFAULT VALUES

!      PURPOSE
!      -------
!      INITIALIZE THE SURFACE SPATIALLY DISTRIBUTED PARAMETERS THAT CAN BE
!      CALIBRATED THROUGH THE READING OF AN EXTERNAL FILE WITH THE DEFAULT VALUES

!      INTERFACE
!      ---------
!      *SUSDP_DFLT* IS CALLED BY *SUINIF1S* AND *SUGRIDG*

!      INPUT PARAMETERS (REAL):
!      *PTVL*        LOW VEGETATION TYPE
!      *PTVH*        HIGH VEGETATION TYPE
!      *PSLT*        SOIL TYPE

!      INPUT PARAMETERS (INTEGER):
!      *KLEVS3D*     NUMBER OF SOIL VERTICAL LEVELS

!      OUTPUT PARAMETERS (REAL):
!      *PSSDP2*      2D OBJECT WITH SURFACE SPATIALLY DISTRIBUTED PARAMETERS
!      *PSSDP3*      3D OBJECT WITH SURFACE SPATIALLY DISTRIBUTED PARAMETERS
!     

!      REFERENCE
!      ---------

!      Original:   Iria Ayan-Miguez (BSC) July 2023

!     --------------------------------------------------------------------------


IMPLICIT NONE

REAL(KIND=JPRB),    INTENT(IN)  :: PTVL(:)
REAL(KIND=JPRB),    INTENT(IN)  :: PTVH(:)
REAL(KIND=JPRB),    INTENT(IN)  :: PSLT(:)
REAL(KIND=JPRB),    INTENT(OUT) :: PSSDP2(:,:)
REAL(KIND=JPRB),    INTENT(OUT) :: PSSDP3(:,:,:)
INTEGER(KIND=JPIM), INTENT(IN)  :: KLEVS3D
TYPE(TVEG),         INTENT(IN)  :: YDVEG
TYPE(TSOIL),        INTENT(IN)  :: YDSOIL
TYPE(TAGS),         INTENT(IN)  :: YDAGS

INTEGER(KIND=JPIM) :: JK
REAL(KIND=JPHOOK) :: ZHOOK_HANDLE

IF (LHOOK) CALL DR_HOOK('SUSDP_DFLT_CTL_MOD:SUSDP_DFLT_CTL',0,ZHOOK_HANDLE)
ASSOCIATE(RVCOVH2D=>PSSDP2(:,SSDP2D_ID%NRVCOVH2D), RVCOVL2D=>PSSDP2(:,SSDP2D_ID%NRVCOVL2D),&
    & RVHSTRH2D=>PSSDP2(:,SSDP2D_ID%NRVHSTRH2D), RVHSTRL2D=>PSSDP2(:,SSDP2D_ID%NRVHSTRL2D),&    
    & RVLAMSKH2D=>PSSDP2(:,SSDP2D_ID%NRVLAMSKH2D), RVLAMSKL2D=>PSSDP2(:,SSDP2D_ID%NRVLAMSKL2D),&
    & RVLAMSKSH2D=>PSSDP2(:,SSDP2D_ID%NRVLAMSKSH2D), RVLAMSKSL2D=>PSSDP2(:,SSDP2D_ID%NRVLAMSKSL2D),&
    & RVRSMINH2D=>PSSDP2(:,SSDP2D_ID%NRVRSMINH2D), RVRSMINL2D=>PSSDP2(:,SSDP2D_ID%NRVRSMINL2D),& 
    & RVZ0MH2D=>PSSDP2(:,SSDP2D_ID%NRVZ0MH2D), RVZ0ML2D=>PSSDP2(:,SSDP2D_ID%NRVZ0ML2D),&
    & RVZ0HH2D=>PSSDP2(:,SSDP2D_ID%NRVZ0HH2D), RVZ0HL2D=>PSSDP2(:,SSDP2D_ID%NRVZ0HL2D),&
    & RVRSMINB2D=>PSSDP2(:,SSDP2D_ID%NRVRSMINB2D),&
    & RVRO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2IL2D=>PSSDP2(:,SSDP2D_ID%NRVF2IL2D),&
    & RVFZEROSTH2D=>PSSDP2(:,SSDP2D_ID%NRVFZEROSTH2D), RVFZEROSTL2D=>PSSDP2(:,SSDP2D_ID%NRVFZEROSTL2D),&
    & RVGAMMH2D=>PSSDP2(:,SSDP2D_ID%NRVGAMMH2D), RVGAMML2D=>PSSDP2(:,SSDP2D_ID%NRVGAMML2D),&
    & RVGCH2D=>PSSDP2(:,SSDP2D_ID%NRVGCH2D), RVGCL2D=>PSSDP2(:,SSDP2D_ID%NRVGCL2D),&
    & RVGMESH2D=>PSSDP2(:,SSDP2D_ID%NRVGMESH2D), RVGMESL2D=>PSSDP2(:,SSDP2D_ID%NRVGMESL2D),&
    & RVLAIMINH2D=>PSSDP2(:,SSDP2D_ID%NRVLAIMINH2D), RVLAIMINL2D=>PSSDP2(:,SSDP2D_ID%NRVLAIMINL2D),&
    & RVQDAMMAXH2D=>PSSDP2(:,SSDP2D_ID%NRVQDAMMAXH2D), RVQDAMMAXL2D=>PSSDP2(:,SSDP2D_ID%NRVQDAMMAXL2D),&   
    & RVQDGAMMH2D=>PSSDP2(:,SSDP2D_ID%NRVQDGAMMH2D), RVQDGAMML2D=>PSSDP2(:,SSDP2D_ID%NRVQDGAMML2D),&
    & RVQDGMESH2D=>PSSDP2(:,SSDP2D_ID%NRVQDGMESH2D), RVQDGMESL2D=>PSSDP2(:,SSDP2D_ID%NRVQDGMESL2D),&
    & RVSEFOLDH2D=>PSSDP2(:,SSDP2D_ID%NRVSEFOLDH2D), RVSEFOLDL2D=>PSSDP2(:,SSDP2D_ID%NRVSEFOLDL2D),&
    & RVT1AMMAXH2D=>PSSDP2(:,SSDP2D_ID%NRVT1AMMAXH2D), RVT1AMMAXL2D=>PSSDP2(:,SSDP2D_ID%NRVT1AMMAXL2D),& 
    & RVT1GMESH2D=>PSSDP2(:,SSDP2D_ID%NRVT1GMESH2D), RVT1GMESL2D=>PSSDP2(:,SSDP2D_ID%NRVT1GMESL2D),&
    & RVT2AMMAXH2D=>PSSDP2(:,SSDP2D_ID%NRVT2AMMAXH2D), RVT2AMMAXL2D=>PSSDP2(:,SSDP2D_ID%NRVT2AMMAXL2D),& 
    & RVT2GMESH2D=>PSSDP2(:,SSDP2D_ID%NRVT2GMESH2D), RVT2GMESL2D=>PSSDP2(:,SSDP2D_ID%NRVT2GMESL2D),&
    & RVTOPTH2D=>PSSDP2(:,SSDP2D_ID%NRVTOPTH2D), RVTOPTL2D=>PSSDP2(:,SSDP2D_ID%NRVTOPTL2D),&
    & RXBOMEGAMH2D=>PSSDP2(:,SSDP2D_ID%NRXBOMEGAMH2D), RXBOMEGAML2D=>PSSDP2(:,SSDP2D_ID%NRXBOMEGAML2D))


! Vegetation Parameters

RVCOVH2D(:)    = YDVEG%RVCOV(PTVH(:))
RVCOVL2D(:)    = YDVEG%RVCOV(PTVL(:))
RVHSTRH2D(:)   = YDVEG%RVHSTR(PTVH(:))
RVHSTRL2D(:)   = YDVEG%RVHSTR(PTVL(:))
RVLAMSKH2D(:)  = YDVEG%RVLAMSK(PTVH(:))
RVLAMSKL2D(:)  = YDVEG%RVLAMSK(PTVL(:))
RVLAMSKSH2D(:) = YDVEG%RVLAMSKS(PTVH(:))
RVLAMSKSL2D(:) = YDVEG%RVLAMSKS(PTVL(:))
RVRSMINH2D(:)  = YDVEG%RVRSMIN(PTVH(:))
RVRSMINL2D(:)  = YDVEG%RVRSMIN(PTVL(:))
RVZ0MH2D(:)    = YDVEG%RVZ0M(PTVH(:))
RVZ0ML2D(:)    = YDVEG%RVZ0M(PTVL(:))
RVZ0HH2D(:)    = YDVEG%RVZ0H(PTVH(:))
RVZ0HL2D(:)    = YDVEG%RVZ0H(PTVL(:))
RVRSMINB2D(:)  = 50.0_JPRB

DO JK=1, KLEVS3D
  RVROOTSAH3D(:,JK) = YDVEG%RVROOTSA(JK, PTVH(:))
  RVROOTSAL3D(:,JK) = YDVEG%RVROOTSA(JK, PTVL(:))
ENDDO

! Soil Parameters

RCGDRYM3D(:,:)  = 1.6E6_JPRB 
DO JK=1, KLEVS3D
  RLAMBDAM3D(:,JK) = YDSOIL%RLAMBDAM(PSLT(:))
  RMVGALPHA3D(:,JK)= YDSOIL%RMVGALPHA(PSLT(:))
  RNFACM3D(:,JK)   = YDSOIL%RNFACM(PSLT(:))
  RWCONSM3D(:,JK)  = YDSOIL%RWCONSM(PSLT(:))
  RWRESTM3D(:,JK)  = YDSOIL%RWRESTM(PSLT(:))
  RWSATM3D(:,JK)   = YDSOIL%RWSATM(PSLT(:))
ENDDO

! Ags Parameters

RVAHL2D(:)    = YDAGS%RVAH(PTVL(:))
RVAMMAXH2D(:) = YDAGS%RVAMMAX(PTVH(:))
RVAMMAXL2D(:) = YDAGS%RVAMMAX(PTVL(:))
RVBHL2D(:)    = YDAGS%RVBH(PTVL(:))
RVCEH2D(:)    = YDAGS%RVCE(PTVH(:)) 
RVCEL2D(:)    = YDAGS%RVCE(PTVL(:)) 
RVCFH2D(:)    = YDAGS%RVCF(PTVH(:)) 
RVCFL2D(:)    = YDAGS%RVCF(PTVL(:)) 
RVCNAH2D(:)   = YDAGS%RVCNA(PTVH(:)) 
RVCNAL2D(:)   = YDAGS%RVCNA(PTVL(:)) 
RVDMAXH2D(:)  = YDAGS%RVDMAX(PTVH(:))  
RVDMAXL2D(:)  = YDAGS%RVDMAX(PTVL(:))  
RVEPSOH2D(:)  = YDAGS%RVEPSO(PTVH(:))
RVEPSOL2D(:)  = YDAGS%RVEPSO(PTVL(:))
RVF2IH2D(:)   = YDAGS%RVF2I(PTVH(:))
RVF2IL2D(:)   = YDAGS%RVF2I(PTVL(:))
RVFZEROSTH2D(:) = YDAGS%RVFZEROST(PTVH(:))     
RVFZEROSTL2D(:) = YDAGS%RVFZEROST(PTVL(:))     
RVGAMMH2D(:)  = YDAGS%RVGAMM(PTVH(:))  
RVGAMML2D(:)  = YDAGS%RVGAMM(PTVL(:))
RVGCH2D(:)    = YDAGS%RVGC(PTVH(:))
RVGCL2D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